# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=cborg-json
pkgname=haskell-cborg-json
pkgver=0.2.5.0
pkgrel=67
pkgdesc="A library for encoding JSON as CBOR"
url="https://github.com/well-typed/cborg-json"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-aeson-pretty' 'haskell-cborg' 'haskell-scientific'
         'haskell-unordered-containers' 'haskell-vector')
makedepends=('ghc' 'uusi')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('0f2ff692915a882e6531cdbfa9a41038ed1189fbd3e428676511998a668e6a700ebe7142c30de4a9ab8dc7738002517a0fa7d9af7a4a34a6389eee9ce912c3be')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u vector $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.txt
}
